//
//  BRPendingHeaderView.m
//  BrezzeSaaS
//
//  Created by IOS on 2022/4/15.
//  Copyright © 2022 Brezze GWG. All rights reserved.
//

#import "BRPendingHeaderView.h"

@interface BRPendingHeaderView ()
{
    UIView *_rDot;
    QMUILabel *_titleL;
    QMUILabel *_subTitleL;
}

@end

@implementation BRPendingHeaderView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
    }
    return self;
}

- (void)setState:(NSInteger)state {
    _state = state;
    NSString *str = state == 0 ? Localized(@"Order_pending") : Localized(@"Order_submitted");
    _titleL.text = str;
    _subTitleL.hidden = state != 0;
    _rDot.hidden = _subTitleL.hidden;
    for (int i = 0; i < 3; i++) {
        
        NSString *imgStr = [NSString stringWithFormat:@"order_pending%ld",i + state];
        UIImageView *pendingImg = [self viewWithTag:1000 + i];
        pendingImg.image = UIImageMake(imgStr);
        pendingImg.hidden = NO;
        if (state != 0 && i == 2) {
            pendingImg.hidden = YES;
        }
    }
    
}

#pragma mark - UI --
- (void)setUI {
    
    self.backgroundColor = UIColor.qd_backgroundColor2;
    self.layer.cornerRadius = kCorners;
    self.layer.masksToBounds = YES;
 
    for (int i = 0; i < 3; i++) {
        NSString *imgStr = [NSString stringWithFormat:@"order_pending%d",i];
        UIImageView *pendingImg = [[UIImageView alloc] init];
        pendingImg.image = UIImageMake(imgStr);
        [self addSubview:pendingImg];
        pendingImg.tag = 1000 + i;
        CGFloat img_w = 35.f;
        CGFloat img_y = 26.5;
        CGFloat img_x = 28.;
        if (i == 1) {
            img_w = 56.f;
            img_y = 16.f;
        }
        if (i == 2) pendingImg.alpha = 0.2;
        [pendingImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.mas_equalTo(img_w);
            make.top.offset(img_y);
            if (i == 1) {
                make.centerX.offset(0);
            }else if (i == 0) {
                make.left.offset(img_x);
            }else {
                make.right.offset(-img_x);
            }
        }];
    }
    CGFloat pa_x = (kScreenWidth - 300) / 4.f;
    CGFloat dot_x = pa_x + 64;
    //58
    UIView *lDot = [self dotsView:0];
    [self addSubview:lDot];
    [lDot mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(dot_x);
        make.height.mas_equalTo(36);
        make.top.offset(26.5);
        make.width.mas_equalTo(58);
    }];
    UIView *rDot = [self dotsView:1];
    [self addSubview:rDot];
    [rDot mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-dot_x);
        make.height.mas_equalTo(36);
        make.top.offset(26.5);
        make.width.mas_equalTo(58);
    }];
    _rDot = rDot;
    
    QMUILabel *titleL = [[QMUILabel alloc] init];
    titleL.text = Localized(@"Order_pending");
    titleL.textAlignment = NSTextAlignmentCenter;
    titleL.textColor = [UIColor qd_titleTextColor];
    titleL.font = [UIFont br_fontB:21];
    [self addSubview:titleL];
    [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(80);
    }];
    QMUILabel *subTitleLB = [[QMUILabel alloc] init];
    subTitleLB.text = Localized(@"Order_submitText");
    subTitleLB.textAlignment = NSTextAlignmentCenter;
    subTitleLB.textColor = [UIColor qd_titleTextColor2];
    subTitleLB.font = [UIFont br_fontM:12];
    [self addSubview:subTitleLB];
    [subTitleLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.bottom.offset(-12);
        make.left.offset(12);
        make.right.offset(-12);
    }];
    
    _titleL = titleL;
    _subTitleL = subTitleLB;
    
}

- (UIView *)dotsView:(NSInteger)type {
    UIView *dotbgV = [UIView new];
    NSArray *dots_w = @[@4,@6,@8,@8,@8];
    if (type == 1) {
        dots_w = [[dots_w reverseObjectEnumerator] allObjects];
    }
    UIView *oDotV;
    for (int i = 0; i < dots_w.count; i++) {
        CGFloat dot_w  = [dots_w[i] floatValue];
        UIView *dot = [[UIView alloc] init];
        dot.layer.cornerRadius = dot_w / 2;
        dot.layer.masksToBounds = YES;
        dot.backgroundColor = UIColor.qd_backgroundColorLighten3;
        dot.backgroundColor = UIColorMake(210, 216, 226);
        [dotbgV addSubview:dot];
        [dot mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.mas_equalTo(dot_w);
            make.centerY.offset(0);
            if (i == 0) {
                make.left.offset(0);
            }else {
                make.left.equalTo(oDotV.mas_right).offset(6);
            }
            
        }];
        oDotV = dot;
    }
    return dotbgV;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
